<?php
	private $root_name="";
	private $site_root='';
	private $file_noexist = 'file_noexist';
    private $dele_statice_success = 'dele_statice_success';
    private $dele_statice_fail = 'dele_statice_fail';
    private $delete_success = 'delete_success';
    private $delete_fail = 'delete_fail';
    private $statice_success = 'statice_success';
    private $statice_fail = 'staice_fail';
    private $pro_no_statice_name = 'pro_no_statice_name';
    private $art_no_statice_name = 'art_no_statice_name';
    private $howto_no_statice_name = 'howto_no_statice_name';
    private $plate_no_statice_name = 'plate_no_statice_name';
    public function __construct(){
    	$this->root_name = 'http://'.$_SERVER['HTTP_HOST'].'/index.php';
    	$this->site_root = 'http://'.$_SERVER['HTTP_HOST'];
    	parent::__construct();

    }
	
	/* public function index(){
        header("Content-Type:text/html; charset=utf-8");
       $system=M('System');
       $sdata=$system->find();
       $this->assign('use_yzm',$sdata['use_yzm']);
       $this->display();

    } */
	
   

 public function system_info(){
 	$system=M('System');
 	$s=$system->select();
 	if($s){
 		$this->assign('is_exit',1);
 	}

 }

    /* //判断是否登陆
    private function is_login(){
    	header("Content-Type:text/html; charset=utf-8");
    	if(!isset($_SESSION['login_name'])|| !isset($_COOKIE['login_name'])){
    		//$this->display('index');
    		echo "<script>location.href='".__URL__."/index';</script>";
    		exit;
    	}
    	$this->system_info();
    } */
    //进入系统参数页面
    public function system(){
	    	$this->is_login();
	    	$this->display();
    }
    //设置系统全局参数
	public function set_system(){
		$this->is_login();
		if($this->isPost()){
			$system=M('System');
    		if($system->create()){
    			$data['webname']=isset($_POST['web_name'])?trim($_POST['web_name']):'';
    			$data['web_keyword']=isset($_POST['web_keyword'])?trim($_POST['web_keyword']):'';
    			$data['web_discrition']=isset($_POST['web_discrition'])?trim($_POST['web_discrition']):'';
    			$data['use_yzm']=$_POST['yzm'];
    			if($system->add($data)){
    				echo "<script>alert('添加成功');history.back();</script>";
    			}else{
    				echo "<script>alert('添加失败');history.back();</script>";
    			}
    		}else{
    			echo "<script>alert('创建失败');history.back();</script>";
    			return;
    		}
    	}else{
    		$this->display();
    	}
    }

    /* public function modify_system(){
    	$this->is_login();
		if($this->isPost()){
			$system=M('System');

    		$id=isset($_POST['s_id'])?$_POST['s_id']:0;
    		if(!$id){
    			return;
    		}
    		$data['webname']=isset($_POST['web_name'])?trim($_POST['web_name']):'';
    		$data['web_keyword']=isset($_POST['web_keyword'])?trim($_POST['web_keyword']):'';
    		$data['web_discrition']=isset($_POST['web_discrition'])?trim($_POST['web_discrition']):'';
    		$data['use_yzm']=$_POST['yzm'];
    		if($system->where("id=".$id)->save($data)){
    			echo "<script>alert('修改成功');history.back();</script>";
    		}else{
    			echo "<script>alert('修改失败');history.back();</script>";
    		}

    	}else{
    		$s=M("System");
    		$data=$s->find();
    		$this->assign('sdata',$data);
    		$this->display();
    	}
    } */
    //添加一级分类
	public function big_category(){
		$this->is_login();
		if($this->isPost()){
			$bigcategory=M('Bigcategory');
			$data['big_category_name']=isset($_POST['big_cat'])?trim($_POST['big_cat']):'';
			$data['big_title']=isset($_POST['big_title'])?trim($_POST['big_title']):'';
			$data['big_keyword']=isset($_POST['big_keyword'])?trim($_POST['big_keyword']):'';
			$data['statice_name']=isset($_POST['statice_name'])?trim($_POST['statice_name']):'';
			$data['big_description']=isset($_POST['big_description'])?trim($_POST['big_description']):'';
			$data['howto_title']=isset($_POST['howto_title'])?trim($_POST['howto_title']):'';
			$data['howto_keyword']=isset($_POST['howto_keyword'])?trim($_POST['howto_keyword']):'';
			$data['howto_description']=isset($_POST['howto_description'])?trim($_POST['howto_description']):'';
    		$data['add_time']=time();
    		if(!$data['big_category_name']){
    			return;
    		}
    		if($bigcategory->where("big_category_name='".$data['big_category_name']."'")->find()){
    			echo "<script>alert('分类名已存在，请填写其他分类名');history.back();</script>";
    			return;
    		}
			if(!$_FILES){
    			return;
    		}
    		$updata=$this->up();
    		if($updata){
				$data['big_img']=$updata[0]['savename'];
    		}else{
    			echo "<script>alert('上传失败');history.back();</script>";
    			return;
    		}
    		if($bigcategory->add($data)){
    			echo "<script>alert('添加成功');history.back();</script>";
    		}else{
    			echo "<script>alert('添加失败');history.back();</script>";
    		}

    	}else{
    		$this->display();
    	}
    }
    //添加栏目
	public function plate(){
	$this->is_login();
		if($this->isPost()){
			$plate=M('Plate');
			//$data['plate_name']=isset($_POST['plate_name'])?trim($_POST['plate_name']):'';
			$insert['plate_name']=isset($_POST['plate_name'])?trim($_POST['plate_name']):'';
			$insert['plate_title']=isset($_POST['plate_title'])?trim($_POST['plate_title']):'';
			$insert['pid']=isset($_POST['pid'])?trim($_POST['pid']):0;
			$insert['plate_keyword']=isset($_POST['plate_keyword'])?trim($_POST['plate_keyword']):0;
			$insert['statice_name']=isset($_POST['statice_name'])?trim($_POST['statice_name']):'';
			$insert['win_mac_classfy']=isset($_POST['win_mac_classfy'])?trim($_POST['win_mac_classfy']):'1';
			$insert['plate_description']=isset($_POST['plate_dis'])?trim($_POST['plate_dis']):'';
    		$insert['add_time']=time();
    		if(!$insert['plate_name'] || !$insert['pid']){
    			return;
    		}
			if($plate->where("pid=".$insert['pid']." and plate_name='".$insert['plate_name']."'")->find()){
    			echo "<script>alert('栏目名已存在，请填写其他栏目名');history.back();</script>";
    			return;
    		}
    		/*$ret=true;
    		$explode=explode(';', $data['plate_name']);
    		foreach($explode as $k => $v){
    			$insert['plate_name']=$v;
	    		if(!$plate->add($insert)){
	    			$ret=false;
	    		}
    		}*/
    		if($plate->add($insert)){
    			echo "<script>alert('添加成功');location.href='".__URL__."/plate_manage';</script>";
    		}else{
    			echo "<script>alert('添加失败');history.back();</script>";
    		}

    	}else{
    		$bigcategory=M('Bigcategory');
    		$cate=$bigcategory->select();
    		$this->assign('cate',$cate);
    		$this->display();
    	}
    }
    //添加产品
	public function product(){
		$this->is_login();
		if($this->isPost()){
			$product=M('Product');
//			$id=isset($_POST['plate'])?explode(',', $_POST['plate']):'';
//			$data['gid']=$id[0];
			$data['pid']=isset($_POST['plate'])?intval($_POST['plate']):0;
			$data['cid']=isset($_POST['cid'])?intval($_POST['cid']):0;
			$data['product_name']=isset($_POST['p_name'])?trim($_POST['p_name']):'';
			$data['classify_name']=isset($_POST['classify_name'])?trim($_POST['classify_name']):'';
			$data['product_title']=isset($_POST['p_title'])?trim($_POST['p_title']):'';
			$data['buy_link']=isset($_POST['buy_link'])?trim($_POST['buy_link']):'';
			$data['product_keyword']=isset($_POST['product_keyword'])?trim($_POST['product_keyword']):'';
			$data['statice_name']=isset($_POST['statice_name'])?trim($_POST['statice_name']):'';
			$data['download_link']=isset($_POST['download_link'])?trim($_POST['download_link']):'';
			$data['one_download_link']=isset($_POST['one_download_link'])?intval($_POST['one_download_link']):1;
			$data['is_popular']=isset($_POST['popular'])?intval($_POST['popular']):0;
			$data['is_hot']=isset($_POST['hot'])?intval($_POST['hot']):0;
			$data['hot_show']=isset($_POST['hot_show'])?intval($_POST['hot_show']):0;
			$data['is_new']=isset($_POST['is_new'])?intval($_POST['is_new']):0;
			$data['market_price']=isset($_POST['market_price'])?floatval($_POST['market_price']):'0.00';
			$data['now_price']=isset($_POST['now_price'])?floatval($_POST['now_price']):'0.00';
			$data['size']=isset($_POST['size'])?trim($_POST['size']):'';
			$data['relative_product']=isset($_POST['rp'])?trim($_POST['rp'],','):'';
			$data['introduce']=isset($_POST['introduce'])?trim($_POST['introduce']):'';
			if (get_magic_quotes_gpc()) {
				$data['content'] = isset($_POST['product_content'])?stripslashes($_POST['product_content']):'';
				$data['sec_description'] = isset($_POST['sec_description'])?stripslashes($_POST['sec_description']):'';
			} else {
				$data['content'] = isset($_POST['product_content'])?trim($_POST['product_content']):'';
				$data['sec_description'] = isset($_POST['sec_description'])?trim($_POST['sec_description']):'';
			}
			//$data['content']=isset($_POST['product_content'])?trim($_POST['product_content']):'';
    		$data['add_time']=time();
    		$data['pc']=isset($_POST['pc'])?trim($_POST['pc']):0;
    		$data['out_link']=isset($_POST['out_link'])?trim($_POST['out_link']):'';
    		$data['price_down_range']=isset($_POST['price_down_range'])?trim($_POST['price_down_range']):'';
    		$width=isset($_POST['width'])?trim($_POST['width']):0;
    		$height=isset($_POST['height'])?trim($_POST['height']):0;
    		if(!$data['product_name']){
    			return;
    		}
			if($product->where("pid=".$data['pid']." and product_name='".$data['product_name']."'")->find()){
    			echo "<script>alert('产品名已存在，请填写其他产品名');history.back();</script>";
    			return;
    		}
    		if(!$_FILES){
    			return;
    		}
    		$updata=$this->up($width,$height);

    		if($updata){
    			foreach($updata as $v){
    				if($v['key'] == 't_img'){
    					$data['product_img']=$v['savename'];
    				}elseif($v['key'] == 'sec_img'){
    					$data['sec_img']=$v['savename'];
    				}elseif($v['key'] == 'three_img'){
    					$data['three_img']=$v['savename'];
    				}
    			}
//				$data['product_img']=$updata[0]['savename'];
    		}else{
    			echo "<script>alert('上传失败');history.back();</script>";
    			return;
    		}
    		if($product->data($data)->add()){
    			echo "<script>alert('添加成功');location.href='".__URL__."/product_manage';</script>";
    		}else{
    			echo "<script>alert('添加失败');history.back();</script>";
    		}

    	}else{
    		$product=M('Product');
    		$bigcategory=M('Bigcategory');
    		$cate=$bigcategory->select();
    		$this->assign('cate',$cate);
    		$plate=M('Plate');
    		$plate=$plate->select();
    		$this->assign('plate',$plate);

	    	$allpro=$product->field('think_product.*,b.big_category_name')->join('left join think_bigcategory b on b.id=think_product.pid')->order('b.id')->select();

	    	$this->assign('allpro',$allpro);

	    	$art_classify = M("ArticleClassify");
    		$ac_data=$art_classify->field('think_article_classify.*,b.big_category_name')->join('left join think_bigcategory b on b.id=think_article_classify.pid')->select();
    		$this->assign('ac_data',$ac_data);
    		$this->display();
    	}
    }

    //上传文件
    private function up($width=0,$height=0){
    	$width=$width==0?'150':$width;
    	$height=$height==0?'100':$height;
    	import('@.Org.UploadFile');
			$upload=new UploadFile();
			$upload->maxSize='1000000';  //是指上传文件的大小，默认为-1,不限制上传文件大小bytes
			$upload->savePath='./Public/upload/';       //上传保存到什么地方？路径建议大家已主文件平级目录或者平级目录的子目录来保存
			$upload->saveRule=uniqid;    //上传文件的文件名保存规则  time uniqid  com_create_guid  uniqid
			//$upload->autoCheck=false   ;  //是否自动检测附件
			$upload->uploadReplace=true;     //如果存在同名文件是否进行覆盖
			$upload->allowExts=array('jpg','jpeg','png','gif');     //准许上传的文件后缀
			$upload->allowTypes=array('image/png','image/jpg','image/pjpeg','image/gif','image/jpeg');  //检测mime类型
			$upload->thumb=true;   //是否开启图片文件缩略
			$upload->thumbMaxWidth=$width;  //以字串格式来传，如果你希望有多个，那就在此处，用,分格，写上多个最大宽
			$upload->thumbMaxHeight=$height;	//最大高度
			$upload->thumbPrefix='s_,m_';//缩略图文件前缀
			//$upload->thumbSuffix='_s,_m';  //文件后缀
			//$upload->thumbPath='' ;  // 如果留空直接上传至
			//$upload->thumbFile   在数据库当中也存一个文件名即可
			$upload->thumbRemoveOrigin=0;  //如果生成缩略图，是否删除原图 1是0否
			//$upload->autoSub   是否使用子目录进行保存上传文件
			//$upload->subType=''   子目录创创方式默认为hash 也可以设为date
			//$upload->dateFormat  子目录方式date的指定日期格式
			//$upload->hashLevle

		if(!$upload->upload()) { //  上传错误 提示错误信息

			//$this->error($upload->getErrorMsg());
			return false;

		}else{ //  上传成功 获取上传文件信息

			return $upload->getUploadFileInfo();

		 }
    }

    
//产品多链接管理
    public function product_download_link_manage(){
    	$this->is_login();
    	$pdl=M('ProductDownloadLink');
    	$cate=$pdl->select();
    	$this->assign('cate',$cate);
    	$this->display();
    }

 
	
	

	

    //栏目管理
    public function plate_manage(){
    	$this->is_login();
    	$bigcategory=M('Bigcategory');
    	$cate=$bigcategory->select();
//    	$plate=M('Plate');
//    	$plate=$plate->select();
    	$product=M('Product');
    	$article=M('Article');
    	foreach($cate as $k => $v){
    		$cate[$k]['art_num']=$article->where('pid='.$v['id'])->count();
    		$cate[$k]['pro_num']=$product->where('pid='.$v['id'])->count();
    	}
    	$this->assign('cate',$cate);
//    	$this->assign('plate',$plate);
    	$this->display();
    }
    //更改大类名称
     public function change_big_cate(){
     	$this->is_login();
     	if($this->isPost()){
     	$id=isset($_POST['cate_id'])?intval($_POST['cate_id']):0;
     		$cate_name=isset($_POST['change_name'])?trim($_POST['change_name']):'';
     		$big_title=isset($_POST['big_title'])?trim($_POST['big_title']):'';
     		$big_keyword=isset($_POST['big_keyword'])?trim($_POST['big_keyword']):'';
     		$big_description=isset($_POST['big_description'])?trim($_POST['big_description']):'';
     		$howto_title=isset($_POST['howto_title'])?trim($_POST['howto_title']):'';
			$howto_keyword=isset($_POST['howto_keyword'])?trim($_POST['howto_keyword']):'';
			$howto_description=isset($_POST['howto_description'])?trim($_POST['howto_description']):'';

     		if(!$id || !$cate_name){
     			return;
     		}
     		$bigcategory=M('Bigcategory');
     		$data['big_category_name']=$cate_name;
     		$data['big_title']=$big_title;
     		$data['big_description']=$big_description;
     		$data['howto_title']=$howto_title;
			$data['howto_keyword']=$howto_keyword;
			$data['howto_description']=$howto_description;
     		$data['statice_name']=isset($_POST['statice_name'])?trim($_POST['statice_name']):'';
     		if($bigcategory->where("id!=".$id." and big_category_name='".$data['big_category_name']."'")->find()){
    			echo "<script>alert('分类名已存在，请填写其他分类名');history.back();</script>";
    			return;
    		}
     		if($big_keyword){
     			$data['big_keyword']=$big_keyword;
     		}

    		$updata=$this->up();
    		if($updata){
				$data['big_img']=$updata[0]['savename'];
    		}
     		if($bigcategory->where("id=$id")->save($data)){
     			echo "<script>alert('修改成功');location.href='".__URL__."/plate_manage';</script>";
     		}else{
     			echo "<script>alert('修改失败');history.back();</script>";
     		}
     	}else{
	     	$bigcategory=M('Bigcategory');
	     	$id=$_GET['id'];
	     	if(!$id){
	     		return;
	     	}
	     	$data=$bigcategory->find($id);
	     	$this->assign('cate',$data);
	     	$this->display();
     	}
     }
	//更改栏目名称
     public function modify_plate(){
     $this->is_login();
     	if($this->isPost()){
     		$pid=isset($_POST['pid'])?intval($_POST['pid']):0;
     		$id=isset($_POST['plate_id'])?intval($_POST['plate_id']):0;
     		$plate_name=isset($_POST['change_name'])?trim($_POST['change_name']):'';
     		$plate_title=isset($_POST['plate_title'])?trim($_POST['plate_title']):'';
     		$plate_keyword=isset($_POST['plate_keyword'])?trim($_POST['plate_keyword']):'';

     		if(!$id || !$plate_name){
     			return;
     		}
     		$plate=M('Plate');
     		$data['plate_name']=$plate_name;
     		$data['plate_title']=$plate_title;
     		$data['win_mac_classfy']=isset($_POST['win_mac_classfy'])?trim($_POST['win_mac_classfy']):'1';
     		if($plate->where("id!=".$id." and pid=".$pid." and plate_name='".$plate_name."'")->find()){
    			echo "<script>alert('此分类栏目名已存在，请填写其他栏目名');history.back();</script>";
    			return;
    		}
     		if($plate_keyword){
     			$data['plate_keyword']=$plate_keyword;
     		}
     		if(isset($_POST['plate_dis']) && $_POST['plate_dis']!=''){
     			$data['plate_description']=isset($_POST['plate_dis'])?trim($_POST['plate_dis']):'';
     		}
     		$data['statice_name']=isset($_POST['statice_name'])?trim($_POST['statice_name']):'';
     		if($plate->where("id=$id")->save($data)){
     			echo "<script>alert('修改成功');location.href='".__URL__."/plate_manage';</script>";
     		}else{
     			echo "<script>alert('修改失败');history.back();</script>";
     		}
     	}else{
	     	$plate=M('Plate');
	     	$id=$_GET['id'];
	     	if(!$id){
	     		return;
	     	}
	     	$data=$plate->find($id);
	     	$this->assign('plate',$data);
	     	$this->display();
     	}
     }

     //删除静态化文件   传入一个数组
     function delete_statice_file($arr){
     	if(is_array($arr)){
     		foreach($arr as $k => $v){
     			if($v['statice_name'] && file_exists($v['statice_name'].'.html')){
     				unlink($v['statice_name'].'.html');
     			}
     		}
     	}
     }

 	//删除大类
    public function delete_big_cate(){
    	header("Content-Type:text/html; charset=utf-8");
    	$this->is_login();
     	$id=$_GET['id'];
      	if (!$id){
     		return;
     	}

     	$bigcategory=M('Bigcategory');
     	$plate=M('Plate');
     	$article=M('Article');
     	$product=M('Product');
     	$bdata=$bigcategory->find($id);
     	$pdata=$plate->where('pid='.$id)->select();
     	$prodata=$product->where('gid='.$id)->select();
     	$adata=$article->where('gid='.$id)->select();

     	//删除大类同时删除相关静态化文件
     	if($bdata['statice_name'] && file_exists($bdata['statice_name'].'.html')){
     		unlink($bdata['statice_name'].'.html');
     	}
     	$this->delete_statice_file($pdata);
     	$this->delete_statice_file($prodata);
     	$this->delete_statice_file($adata);

     	$bret=$bigcategory->where("id=$id")->delete();
     	$pret=$plate->where("pid=$id")->delete();
     	$aret=$article->where("gid=$id")->delete();
     	$prret=$product->where("gid=$id")->delete();
     	if(!$bret){
//     		echo "<script>alert('删除大类失败');history.back();</script>";
     		echo $this->delete_fail;
     		return;
     	}else{
//     		echo "<script>alert('删除大类成功');location.href='".__URL__."/plate_manage';</script>";
			echo $this->delete_success;
     		return;
     	}
     }

	//删除栏目
    public function delete_plate(){
    	header("Content-Type:text/html; charset=utf-8");
    	$this->is_login();
     	$id=$_GET['id'];
      	if (!$id){
     		return;
     	}
     	$plate=M('Plate');
     	$article=M('Article');
     	$product=M('Product');

     	$pdata=$plate->find($id);
     	$prodata=$product->where('pid='.$id)->select();
     	$adata=$article->where('pid='.$id)->select();

     	//删除大类同时删除相关静态化文件
     	if($pdata['statice_name'] && file_exists($pdata['statice_name'].'.html')){
     		unlink($pdata['statice_name'].'.html');
     	}
     	$this->delete_statice_file($prodata);
     	$this->delete_statice_file($adata);

     	$pret=$plate->where("id=$id")->delete();
     	$aret=$article->where("pid=$id")->delete();
     	$prret=$product->where("pid=$id")->delete();
    	if(!$pret){
//     		echo "<script>alert('删除栏目失败');history.back();</script>";
     		echo $this->delete_fail;
     		return;
     	}else{
     		echo $this->delete_success;
     		return;
//     		echo "<script>alert('删除栏目成功');location.href='".__URL__."/plate_manage';</script>";
     	}
     }

	

	
    

 	
	//删除文章
    public function delete_article(){
    	header("Content-Type:text/html; charset=utf-8");
    	$this->is_login();
     	$id=$_GET['id'];
      	if (!$id){
     		return;
     	}
     	$article=M('Article');
     	$adata=$article->find($id);
    	//删除大类同时删除相关静态化文件
     	if($adata['statice_name'] && file_exists($adata['statice_name'].'.html')){
     		unlink($adata['statice_name'].'.html');
     	}
     	$ret=$article->where("id=$id")->delete();
    	if(!$ret){
//     		echo "<script>alert('删除文章失败');history.back();</script>";
			echo $this->delete_fail;
			return;
     	}else{
//     		echo "<script>alert('删除文章成功');location.href='".__URL__."/article_manage';</script>";
			echo $this->delete_success;
     	}
     }
     
    public function exit_login(){
    	unset($_COOKIE['login_name']);
    	unset($_SESSION['login_name']);
    	echo "<script>location.href='".__URL__."/index'</script>";
    }
    
	

	
	//静态化howto页
 	public function howto_statice(){
		header("Content-Type:text/html; charset=utf-8");
    	$id=$_GET['id'];
    	if(!$id){
    		return;
    	}
    	$bigcategory=M('Bigcategory');
    	$data=$bigcategory->find($id);
    	if(!$data['statice_name']){
//    		echo "<script>alert('请先为大类添加howto页静态化名称');location.href='".__URL__."/change_big_cate/id/".$id."';</script>";
    		echo $this->howto_no_statice_name;
    		return;
    	}
		$p=file_get_contents($this->root_name.'/Index/howto/id/'.$id.'/type/select');
	   	if(file_put_contents($data['statice_name'].'.html', $p)){
	   		$bigcategory->where('id='.$id)->save(array('is_statice'=>'1'));
//	   		echo "<script>alert('静态化成功');location.href='".__URL__."/plate_manage';</script>";
			echo $this->statice_success;
			return;
	   	}else{
//    		echo "<script>alert('静态化失败');history.back();</script>";
    		echo $this->statice_fail;
    	}
    }

	//静态化全部howto页
 	public function staticeAllHowto(){
 		header("Content-Type:text/html; charset=utf-8");
    	$bigcategory=M('Bigcategory');
    	$data=$bigcategory->where('statice_name != ""')->select();
    	foreach($data as $v){
    		$id=$v['id'];
			if(!$id){
				return;
			}
			if(empty($v['statice_name'])){
				continue;
			}
			$p=file_get_contents($this->root_name.__ROOT__.'/Index/howto/id/'.$id.'/type/select');
		   	if(file_put_contents("./".$v['statice_name'].'.html', $p)){
		   		$bigcategory->where('id='.$id)->save(array('is_statice'=>'1'));
		   	}else{
	    		echo "<script>alert('静态化失败');history.back();</script>";
	    	}
    	}
   		echo "<script>alert('静态化成功');location.href='".__URL__."/plate_manage';</script>";
    }
	


    //删除howto静态化页面
    Public function delete_howto_statice(){
    	header("Content-Type:text/html; charset=utf-8");
    	$id=$_GET['id'];
    	if(!$id){
    		return;
    	}
    	$bigcategory=M('Bigcategory');
    	$bdata=$bigcategory->find($id);

     	//删除相关静态化文件
     	if($bdata['statice_name'] && file_exists($bdata['statice_name'].'.html')){
     		unlink($bdata['statice_name'].'.html');
     	}else{
//     		echo "<script>alert('静态化文件不存在');history.back();</script>";
     		echo $this->file_noexist;
     		return;
     	}
     	$data['is_statice']=0;
    	if($bigcategory->where("id=$id")->save($data)){
//     			echo "<script>alert('删除成功');location.href='".__URL__."/plate_manage';</script>";
			echo $this->dele_statice_success;
			return;
     	}else{
//     		echo "<script>alert('删除失败');history.back();</script>";
			echo $this->dele_statice_fail;
     	}
    }

	//删除静态化栏目页
 	public function delete_plate_statice(){
 		header("Content-Type:text/html; charset=utf-8");
    	$id=$_GET['id'];
    	$pid=$_GET['pid'];
    	if(!$id || !$pid){
    		return;
    	}
    	$plate=M('Plate');
    	$pdata=$plate->find($id);
 		//删除相关静态化文件
     	if($pdata['statice_name'] && file_exists($pdata['statice_name'].'.html')){
     		unlink($pdata['statice_name'].'.html');
     	}else{
//     		echo "<script>alert('静态化文件不存在');history.back();</script>";
     		echo $this->file_noexist;
     		return;
     	}
     	$data['is_statice']=0;
    	if($plate->where("id=$id")->save($data)){
//     		echo "<script>alert('删除成功');location.href='".__URL__."/plate_manage';</script>";
     		echo $this->dele_statice_success;
     		return;
     	}else{
//     		echo "<script>alert('删除失败');history.back();</script>";
			echo $this->dele_statice_fail;
			return;
     	}
    }

	

  

	public function url($loc,$lastmod,$changefreq,$priority){
		$html='<url>
	　　			  <loc>'.$loc.'</loc>
				　<lastmod>'.$lastmod.'</lastmod>
				　<changefreq>'.$changefreq.'</changefreq>
				　<priority>'.$priority.'</priority>
			　</url> ';
		return $html;
	}

	
	
	
	//产品下载购买信息
    public function product_download_buy_info(){
    	$this->is_login();
    	$bigcategory=M('Bigcategory');
    	$cate=$bigcategory->select();
    	$this->assign('cate',$cate);
//    	$plate=M('Plate');
//    	$plate=$plate->select();
//    	$this->assign('plate',$plate);
    	$dy = M('DownloadBuy');
    	$where = ' 1=1 ';
    	if(!empty($_POST['t_time']) && !empty($_POST['e_time'])){
    		$where .= " and think_download_buy.time >= '".$_POST['t_time']."' and think_download_buy.time <= '".$_POST['e_time']."' ";
    	}else{
    		$where .= " and think_download_buy.time = '".date('Y-m-d')."' ";
    	}
    	$this->assign('s_time',$_POST['t_time']);
    	$this->assign('e_time',$_POST['e_time']);
    	if(!empty($_POST['plate'])){
    		$cid = $_POST['plate'];
    		$where .= " and b.id = $cid";
    		$this->assign('b_id',$cid);

    	}
    	$pdata = $dy->field('think_download_buy.*,sum(think_download_buy.down_num) as d_num,sum(think_download_buy.buy_num) as b_num,pro.product_name,b.big_category_name')    	->join('left join think_product pro on pro.id=think_download_buy.pid left join think_bigcategory b on b.id=pro.pid')    	->group('think_download_buy.pid')->where($where)->select();
    	$this->assign('product',$pdata);
    	$this->display();

    }

    //视频下载email信息
    public function product_download_email(){
    	$this->is_login();

    	$dy = M('email');
    	$where = ' 1=1 ';
    	if(!empty($_POST['t_time']) && !empty($_POST['e_time'])){
    		$where .= " and think_email.time >= '".$_POST['t_time']."' and think_email.time <= '".$_POST['e_time']."' ";
    	}else{
    		$where .= " and think_email.time = '".date('Y-m-d')."' ";
    	}
    	$this->assign('s_time',$_POST['t_time']);
    	$this->assign('e_time',$_POST['e_time']);
    	if(!empty($_POST['plate'])){
    		$cid = $_POST['plate'];

    		$this->assign('b_id',$cid);

    	}
    	$pdata = $dy->field('think_email.*')->where($where)->select();
    	$this->assign('product',$pdata);
    	$this->display();

    }

    

  
    
     
//添加视频信息
     public function dcamera()
    {
   		$this->is_login();
		if($this->isPost()){
			$data['title']=isset($_POST['title'])?trim($_POST['title']):'';
			$data['des']=isset($_POST['des'])?trim($_POST['des']):'';
			$data['download_link']=isset($_POST['download_link'])?trim($_POST['download_link']):'';
			$data['img_addr']=isset($_POST['img_addr'])?trim($_POST['img_addr']):'';
			$data['video_addr']=isset($_POST['video_addr'])?trim($_POST['video_addr']):'';
			$data['version']=isset($_POST['version'])?trim($_POST['deversion']):'';
			$data['author']=isset($_POST['author'])?trim($_POST['author']):'';
			$data['sort']=isset($_POST['sort'])?trim($_POST['sort']):'';
			$data['sub_date'] = date('Y-m-d');

			if(!$data['download_link'] || !$data['img_addr'] || !$data['video_addr'])
			{
				exit('下载链接或图链接或视频链接不能为空');
			}
		$ht = M('camera');
		if($ht->where("title='".$data['title']."' or download_link='".$data['download_link']."'")->find()){
    			echo "<script>alert('标题名已存在，请填写其他标签名 或下载地址已存在');history.back();</script>";

    			return;
    		}
    		if($ht->add($data)){
    			echo "<script>alert('添加成功');location.href='".__URL__."/dcamera';</script>";
    		}else{
    			echo "<script>alert('添加失败');history.back();</script>";
    		}

    	}else{
    		$this->display();
    	}
    }

    //视频信息管理
    public function camera_classify_manage(){
    	$this->is_login();
    	$classify=M('camera');
    	$cate=$classify->field('id,title')->select();
    	$this->assign('cate',$cate);
    	$this->display();
    }

    //更改文章分类名称
     public function modify_camera_classify(){
     $this->is_login();
     	if($this->isPost()){
			$system=M('camera');
    		$isset=isset($_POST['video_addr'])?$_POST['video_addr']:0;
    		$id = $_POST['id'];
    		if(!$isset){
    			return;
    		}
    		if($system->where("id=".$id)->save($_POST)){
    			echo "<script>alert('修改成功');history.back();</script>";
    		}else{
    			echo "<script>alert('修改失败');history.back();</script>";
    		}

    	}else{
    		$s=M("camera");
    		$id=$_GET['id'];
    		$data=$s->where("id=".$id)->find();
    		$this->assign('camera',$data);
    		$this->display();
    	}
     }
     //删除文章分类
    public function delete_camera_classify(){
    	header("Content-Type:text/html; charset=utf-8");
    	$this->is_login();
     	$id=$_GET['id'];
      	if (!$id){
     		return;
     	}
     	$camera_classify=M('camera');
     	$ret=$camera_classify->where("id=$id")->delete();
    	if(!$ret){
			echo $this->delete_fail;
			return;
     	}else{
			echo $this->delete_success;
     	}
     }